﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Threading;

namespace System.Web.Mvc.Html
{
    public static class HtmlHelperLocalizationExtensions
    {        
        /// <summary>
        /// Returns META accept-language tag with the culture supported by current thread
        /// Extension method based on http://www.hanselman.com/blog/GlobalizationInternationalizationAndLocalizationInASPNETMVC3JavaScriptAndJQueryPart1.aspx
        /// </summary>
        /// <typeparam name="T">Type of the model</typeparam>
        /// <param name="html">HTML Helper</param>
        /// <returns>A </returns>
         public static MvcHtmlString MetaAcceptLanguage<T>(this HtmlHelper<T> html)
        {
             var acceptLanguage = GetLocale<T>(html);
             return html.Tag<T>("meta", null, new {@name="accept-language", @content = acceptLanguage });
        }

        /// <summary>
        /// Returns Locale supported by current thread
        /// </summary>
        /// <typeparam name="T">Type of the model</typeparam>
        /// <param name="html">HTML Helper</param>
        /// <returns></returns>
         public static string GetLocale<T>(this HtmlHelper<T> html)
         {
             return Thread.CurrentThread.CurrentUICulture.ToString();
         }
    }
}
